﻿using System.Net;
using __ts.Core.Api;

/*
 *  author: able
 *  @2012/2/21 15:31:59
 * 
 */
namespace __ts.Core.Service
{
    /// <summary>
    /// 
    /// </summary>
    public class OneThreadSelectorStrategy : SelectorStrategy
    {

        /** The processor in charge of the messages processing */
        private SelectorProcessor processor;

        /**
         * Creates an instance of the OneThreadSelectorStrategy class
         * @param selectorFactory The Selector factory to use to create the processor
         */
        public OneThreadSelectorStrategy(SelectorFactory selectorFactory)
        {
            this.processor = selectorFactory.getNewSelector("uniqueSelector", this);
        }

        public SelectorProcessor getSelectorForBindNewAddress()
        {
            return processor;
        }

        public SelectorProcessor getSelectorForNewSession(SelectorProcessor acceptingProcessor)
        {
            return processor;
        }

        public SelectorProcessor getSelectorForWrite(IoSession session)
        {
            return processor;
        }

        public void unbind(SocketAddress address)
        {
            processor.unbind(address);
        }
    }
}
